<template>
    <div class="common-layout">
        <el-container>
            <el-aside width="200px">
                <el-menu :router="true" active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo"
                    default-active="2" text-color="#fff" @open="handleOpen" @close="handleClose">
                    <template v-for="item in menudata">
                        <el-menu-item v-if="!item.children" :index="item.path" >
                            {{item.label}}
                        </el-menu-item>
                        <el-sub-menu v-else :index="item.id">
                            <template #title>
                                <span>{{item.label}}</span>
                            </template>
                            <el-menu-item v-for="sonItem in item.children" :index="sonItem.path" >{{sonItem.label}}</el-menu-item>
                        </el-sub-menu>
                    </template>                    
                </el-menu>
            </el-aside>
            <el-container>
                <el-header>
                    <img class="img" src="../../assets/01.webp" alt="">
                   <div class="huan">欢迎您：{{username}}  <el-button @click="exitFn">退出</el-button></div> 
                   
                </el-header>
                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>
  
<script setup lang="ts">
import {
    Document,
    Menu as IconMenu,
    Location,
    Setting,
} from '@element-plus/icons-vue'
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router';
import getMenus from '../../grants/menudata';
import getRoutes,{clearCurrentRoutes} from "../../grants/router";
const menudata = reactive(getMenus());
getRoutes();

const $router = useRouter();

const handleOpen = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}

// 
const username = ref(sessionStorage.getItem("username"));

const exitFn = ()=>{
    sessionStorage.clear();
    clearCurrentRoutes();//清除当前用户的路由配置；
    $router.push("/Login");
}

</script>

<style scoped>
.common-layout {
    width: 100%;
    height: 100%;
}

.el-container {
    width: 100%;
    height: 100%;
}

.el-aside {
    width: 200px;
    height: 100%;
    background-color:rgb(84, 92, 100);
}

.el-header {
    width: 100%;
    height: 120px;
    background-color: rgb(100, 207, 249);
    padding: 0;
}
.img{
    width: 100%;
    height: 120px;
    /* position: relative; */
    top: 0;
}
.el-header .huan{
    position: absolute;
    top: 0;
    right: 0;
}
</style>